import { mapState, mapMutations } from "vuex";

export default {
    data() {
        return {
            query: {},
            headerHeight: 0, //头部高度
            NavBarHeight: 0, //导航栏高度
            statusBarHeight: 0, //状态栏高度
        };
    },
    onLoad(query) {
        this.query = query;
        this.init && this.init();
    },
    onShow() {
        this.getHeight()
    },
    onHide() {},
    computed: {
        phoneHandle(data) {
            return function(data) {
                if (data) {
                    return data.substr(0, 3) + "****" + data.substr(-4)
                }
            }
        },
        timeHandle(data) {
            return function(data) {
                if (data) {
                    return data.substr(0, 10)
                }

            }
        }

    },
    methods: {
        getStorage(name) {
            return uni.getStorageSync(name);
        },
        setStorage(name, value) {
            return uni.setStorageSync(name, value);
        },
        ...mapMutations(["reload"]),
        toPage(path, query, cb) {
            if (typeof path == "string") {
                uni.navigateTo({
                    url: path,
                    query,
                    success: () => {
                        cb && cb.call(this);
                    },
                });
            } else if (typeof path == "number") {
                uni.navigateBack({
                    delta: Math.abs(path),
                });
            } else {
                const option = path;
                uni[option.type || "navigateTo"]({
                    url: option.path,
                    query: option.query,
                    success: () => {
                        option.cb && option.cb.call(this);
                    },
                });
            }
        },
        //获取导航条高度
        getHeight() {
            let res = uni.getSystemInfoSync() ///微信api方法
            let titleH;
            if (res && res['system']) {
                // 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
                if (res['system'].indexOf('Android') > 0) {
                    titleH = 48
                } else {
                    titleH = 44
                }
                this.NavBarHeight = titleH
                this.statusBarHeight = res['statusBarHeight']
                this.headerHeight = titleH + res['statusBarHeight'];


            }
        },
        copy(data) {
            let _this = this
                //#ifdef H5
            var aux = document.createElement("input");
            aux.setAttribute("value", data);
            document.body.appendChild(aux);
            aux.select();
            document.execCommand("copy");
            document.body.removeChild(aux);
            setTimeout(() => {
                    _this.$message.success('复制成功')
                }, 200)
                // #endif
                //#ifndef H5
            console.log('除h5平台的copy');
            uni.setClipboardData({
                data: data,
                success: function() {
                    _this.$message.success('复制成功')
                }
            });
            //#endif
        },
        //预览大图
        previewBigImg(url) {
            if (Array.isArray(url)) {
                uni.previewImage({
                    urls: url
                })
            } else {
                let array = []
                array.push(url)
                uni.previewImage({
                    urls: array
                })
            }

        },
    },
};